<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName()
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>用户管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>admin/list.action">图书馆管理系统</a>
	</div>

		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#">
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：${sessionScope.ADMIN_SESSION.username}
				    </a>
				</li>
				<li><a href="#"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul>
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
						<input type="text" class="form-control" placeholder="查询内容...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button">
								<i class="fa fa-search" style="padding: 3px 0 3px 0;"></i>
							</button>
						</span>
					</div>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/admin/list.action" class="active">
				      <i class="fa fa-edit fa-fw"></i> 管理员
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/bookInfo/list.action" class="active">
				      <i class="fa fa-dashboard fa-fw" ></i> 图书信息
				    </a>
				</li>
				<li>
                    <a href="${pageContext.request.contextPath }/notice/list.action" class="active">
                		<i class="fa fa-edit fa-fw"></i> 公告
                	</a>
                </li>
                <li>
                	<a href="${pageContext.request.contextPath }/lendList/list.action" class="active">
                		<i class="fa fa-dashboard fa-fw" ></i> 借还信息
                	</a>
                 </li>
				<li>
				    <a href="${pageContext.request.contextPath }/readerInfo/list.action" class="active">
				      <i class="fa fa-edit fa-fw"></i> 读者信息
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/typeInfo/list.action" class="active">
				      <i class="fa fa-dashboard fa-fw" ></i> 图书类型表
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end-->
  </nav>
    <!-- 客户列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">图书信息管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get"
				      action="${pageContext.request.contextPath }/notice/list.action">

					<div class="form-group">
						<label for="topic">话题</label>
						<input type="text" class="form-control" id="topic"
						                   value="${topic }" name="topic" />
					</div>
					<div class="form-group">
						<label for="content">内容</label>
						<input type="text" class="form-control" id="content"
						                   value="${content }" name="content" />
					</div>
					<button type="submit" class="btn btn-primary" >查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal"
		           data-target="#newNoticeDialog" onclick="clearNotice()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">公告信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>话题</th>
								<th>内容</th>
								<th>作者</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.id}</td>
									<td>${row.topic}</td>
									<td>${row.content}</td>
									<td>${row.author}</td>
									<td><center>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#noticeEditDialog" onclick= "editNotice(${row.id})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteNotice(${row.id})">删除</a>

									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath }/notice/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 客户列表查询部分  end-->
</div>
<!-- 创建客户模态框 -->
<div class="modal fade" id="newNoticeDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建公告信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_notice_form">
					<div class="form-group">
						<label for="new_topic" class="col-sm-2 control-label">
						    话题
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_topic" placeholder="图书名称" name="topic" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_content" class="col-sm-2 control-label">内容</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_content" placeholder="作者" name="content" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_author" class="col-sm-2 control-label">作者</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_author" placeholder="出版社" name="author" />
						</div>
					</div>

				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

				<button type="button" class="btn btn-primary" onclick="createNotice()">创建公告</button>

			</div>
		</div>
	</div>
</div>
<!-- 修改客户模态框 -->
<div class="modal fade" id="noticeEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改公告信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_notice_form">
					<input type="hidden" id="edit_id" name="id"/>
					<div class="form-group">
						<label for="edit_topic" class="col-sm-2 control-label">话题</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_topic" placeholder="图书名称" name="topic" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_content" class="col-sm-2 control-label">内容</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_content" placeholder="作者" name="content" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_author" class="col-sm-2 control-label">作者</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_author placeholder="出版社" name="author" />
						</div>
					</div>

				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateNotice()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建客户窗口中的数据
	function clearNotice() {
	    $("#new_topic").val("")
	    $("#new_content").val("")
	    $("#new_author").val("")
	}
	// 创建客户
	function createNotice() {
	$.post("<%=basePath%>notice/create.action",
	$("#new_notice_form").serialize(),function(data){

	            alert("公告创建成功！");
	            window.location.reload();

	    });
	}
	// 通过id获取修改的用户信息
	function editNotice(id) {
	    $.ajax({
	        type:"post",
	        url:"<%=basePath%>notice/getNoticeById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#edit_id").val(data.id);
	            $("#edit_topic").val(data.topic)
	            $("#edit_content").val(data.content)
	            $("#edit_author").val(data.author)
	        }
	    });
	}
    // 执行修改客户操作
	function updateNotice() {
		$.post("<%=basePath%>notice/update.action",
		$("#edit_notice_form").serialize(),function(data){

				alert("公告信息更新成功！");
				window.location.reload();

		});
	}
	// 删除客户


		function deleteNotice(id) {
    	    $.ajax({
    	        type:"post",

    	        url:"<%=basePath%>notice/delete.action",
    	        data:{"id":id},
    	        success:function(data) {
	                alert("公告删除成功！");
	                window.location.reload();
    	        }
    	    });
    	}
</script>
</body>
</html>